package cn.tedu.store.service;


import java.util.Date;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import cn.tedu.store.entity.User;
import cn.tedu.store.service.exception.ServiceException;

@RunWith(SpringRunner.class)
@SpringBootTest
public class UserServiceTestCase {

	@Autowired
	private IUserService userService;
	
	@Test
	public void changeAvatar() {
		try {
			Integer uid = 2;
			String avatar = "upload/2019.jpg";
			userService.changeAvatar(uid, avatar);
			System.err.println("OK.");
		} catch (ServiceException e) {
			System.err.println("错误类型：" + e.getClass().getName());
			System.err.println("错误描述：" + e.getMessage());
		}
	}
	
	@Test
	public void chengInfo() {
		try {
			Date now = new Date();
			User user = new User();
			user.setId(9);
			user.setGender(0);
			user.setGender(1);
			user.setPhone("13800138000");
			user.setEmail("123@qq.com");
			user.setModifiedUser("jungking");
			user.setModifiedTime(now);
			userService.chengeInfo(user);
			System.err.println("OK.");
		} catch (ServiceException e) {
			System.err.println("错误类型：" + e.getClass().getName());
			System.err.println("错误描述：" + e.getMessage());
		}
	}
	
	@Test
	public void changePassword() {
		try {
			Integer uid = 10;
			String oldPassword = "123456";//旧密码
			String newPassword = "123";
			userService.changePassword(uid, oldPassword, newPassword);
			System.err.println("OK.");
		} catch (ServiceException e) {
			System.err.println("错误类型：" + e.getClass().getName());
			System.err.println("错误描述：" + e.getMessage());
		}
	}
	
	
	@Test
	public void login(){
		try {
			String username = "body";
		    String password= "123";
		    User result = userService.login(username, password);
		    System.err.println("result=" + result);
		} catch (ServiceException e) {
			System.err.println("错误类型:"+e.getClass().getName());
			System.err.println("错误描述:"+e.getMessage());
		}
	}
	
	@Test
	public void reg(){
		try {
			Date now = new Date();
			User user = new User();
			user.setUsername("123");
			user.setPassword("123");
			user.setGender(1);
			user.setPhone("10086");
			user.setEmail("12185690@qq.com");
			User rows = userService.reg(user);
			System.out.println(rows);
		} catch (ServiceException e) {
			System.err.println("错误类型:"+e.getClass().getName());
			System.err.println("错误描述:"+e.getMessage());
		}
	}

	@Test
	public void findByUsername(){
		
		
	}

}
